import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

class Request{
    public String from ;
    public String  to ;
    public String  msg ;

    @Override
    public String toString() {
        return "Request{" +
                "from='" + from + '\'' +
                ", to='" + to + '\'' +
                ", msg='" + msg + '\'' +
                '}';
    }
}

@WebServlet("/wall")
public class Wall extends HttpServlet {
     private ObjectMapper objectMapper = new ObjectMapper() ;
     private List<Request> list = new ArrayList<>();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
         Request request = objectMapper.readValue(req.getInputStream() , Request.class) ;
         list.add(request) ;
        System.out.println(request);
         resp.setStatus(200);
         resp.getWriter().write("ok");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String json = objectMapper.writeValueAsString(list);
        resp.setStatus(200);
        resp.setContentType("application/json; charset=utf8");
        resp.getWriter().write(json);

    }
}
